//
//  CustomView.swift
//
//  Code generated using QuartzCode 1.21 on 17/3/23.
//  www.quartzcodeapp.com
//

import UIKit

class CXYLogoView: UIView {
    var Group : CALayer!
    var image : CALayer!
    var image2 : CALayer!
    var image3 : CALayer!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupLayers()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setupLayers()
    }
    
    func setupLayers(){
        Group = CALayer()
        Group.frame = CGRect(x: 0, y: 0, width: 618, height: 480)
        self.layer.addSublayer(Group)
        
        image = CALayer()
        image.frame    = CGRect(x:0, y:0, width:64, height:57)
        image.position = CGPoint(x: self.bounds.width, y: -(UIScreen.main.bounds.height) / 2)
        image.contents = UIImage(named:"an_g")?.cgImage
        Group.addSublayer(image)
        
        image2 = CALayer()
        image2.frame    = CGRect(x:0, y:0, width:43, height:78)
        image2.position = CGPoint(x: 0, y: UIScreen.main.bounds.height / 2)
        image2.setValue(-297.16 * CGFloat(M_PI)/180, forKeyPath:"transform.rotation")
        image2.contents = UIImage(named:"an_r")?.cgImage
        Group.addSublayer(image2)
        
        image3 = CALayer()
        image3.frame    = CGRect(x:0, y:0, width:75, height:52)
        image3.position = CGPoint(x: -self.bounds.width, y: 0)
        image3.setValue(-309.33 * CGFloat(M_PI)/180, forKeyPath:"transform.rotation")
        image3.contents = UIImage(named:"an_b")?.cgImage
        Group.addSublayer(image3)
        Group.position = self.center
    }
    
    
    open func startAllAnimations(sender: AnyObject!){
        Group?.add(GroupAnimation(), forKey:"GroupAnimation")
        image?.add(imageAnimation(), forKey:"imageAnimation")
        image2?.add(image2Animation(), forKey:"image2Animation")
        image3?.add(image3Animation(), forKey:"image3Animation")
    }
    
    func GroupAnimation() -> CABasicAnimation{
        let transformAnim      = CABasicAnimation(keyPath:"transform.rotation")
        transformAnim.toValue  = -720 * CGFloat(M_PI/180);
        transformAnim.duration = 7
        transformAnim.fillMode = kCAFillModeBoth
        transformAnim.repeatCount = Float.infinity;
        transformAnim.isRemovedOnCompletion = false
        
        return transformAnim;
    }
    
    func imageAnimation() -> CAAnimationGroup {
        let transformAnim = CABasicAnimation(keyPath: "transform.rotation")
        transformAnim.toValue = (-364.16 * .pi / 180)
        transformAnim.duration = 4
        
        let positionAnim = CABasicAnimation(keyPath: "position")
        positionAnim.toValue = NSValue(cgPoint: CGPoint(x: CGFloat(320.258), y: CGFloat(209.801)))
        positionAnim.duration = 4
        
        let imageAnimGroup = CAAnimationGroup()
        imageAnimGroup.animations = [transformAnim, positionAnim]
        imageAnimGroup.fillMode = kCAFillModeForwards
        imageAnimGroup.isRemovedOnCompletion = false
        imageAnimGroup.duration = 4
        return imageAnimGroup
    }
    
    func image2Animation() -> CAAnimationGroup{
        let transformAnim      = CABasicAnimation(keyPath:"transform.rotation")
        transformAnim.toValue  = -364.16 * CGFloat(M_PI/180);
        transformAnim.duration = 4
        
        let positionAnim      = CABasicAnimation(keyPath:"position")
        positionAnim.toValue  = NSValue(cgPoint: CGPoint(x:348.289, y:260.176));
        positionAnim.duration = 4
        
        let image2AnimGroup                 = CAAnimationGroup()
        image2AnimGroup.animations          = [transformAnim, positionAnim]
        image2AnimGroup.fillMode            = kCAFillModeForwards
        image2AnimGroup.isRemovedOnCompletion = false
        image2AnimGroup.duration = 4
        return image2AnimGroup;
    }
    
    func image3Animation() -> CAAnimationGroup{
        let transformAnim      = CABasicAnimation(keyPath:"transform.rotation")
        transformAnim.toValue  = -364.16 * CGFloat(M_PI/180);
        transformAnim.duration = 4
        
        let positionAnim      = CABasicAnimation(keyPath:"position")
        positionAnim.toValue  = NSValue(cgPoint: CGPoint(x:289.477, y:256.341));
        positionAnim.duration = 4
        
        let image3AnimGroup                 = CAAnimationGroup()
        image3AnimGroup.animations          = [transformAnim, positionAnim]
        image3AnimGroup.fillMode            = kCAFillModeForwards
        image3AnimGroup.isRemovedOnCompletion = false
        image3AnimGroup.duration = 4
        return image3AnimGroup;
    }
    
}
